//
// Created by 24087 on 2025/5/13.
//

#ifndef INTERFACE_MOTOR_H
#define INTERFACE_MOTOR_H
#include <stdint.h>
#include "Queue2.h"


/*原始角度数据池 --> 队列*/
typedef struct RawAngle
{
	uint8_t rawAngle[7];
	uint8_t motorID;
} RawAngle;

typedef struct
{
	float current_angle;
	uint8_t id;
} MotorInfo;

enum
{
	MAX_MOTOR_NUM = 6
};

extern Queue2 RawAnglePool;
extern MotorInfo MotorPool[MAX_MOTOR_NUM];

typedef enum
{
	HAL_OK2 = 0x00U, // 操作成功
	HAL_ERROR2 = 0x01U, // 操作失败
	HAL_BUSY2 = 0x02U, // 设备或资源忙
	HAL_TIMEOUT2 = 0x03U // 操作超时
} HAL_StatusTypeDef2;

/*原始角度池初始化*/
void RawAnglePool_Init(Queue2 *RawAnglePool);

/*原始角度池销毁*/
void RawAnglePool_Destroy(Queue2 *RawAnglePool);

/*原始角度池入队*/
void RawAnglePool_Push(Queue2 *RawAnglePool, const RawAngle new_rawAngle);

/*原始角度池出队*/
RawAngle RawAnglePool_Pop(Queue2 *RawAnglePool);

/*原始角度池判空*/
bool RawAnglePool_Empty(const Queue2 *RawAnglePool);

/*原始角度池判满*/
bool RawAnglePool_Full(const Queue2 *RawAnglePool);

/*原始角度检查器*/
HAL_StatusTypeDef2 RawAngleData_Check(const uint8_t *angleData);

/*Motor解码器*/
MotorInfo Parser_Motor(RawAngle rawAngle);

/*缓存区搬运*/
void BufferMov_Motor(Queue2 *RawAnglePool, const uint8_t *rawAngleData, const uint8_t ID);

/*电机池更新器*/
void Update_MotorPool(MotorInfo *MotorPool, const MotorInfo new_motorInfo);

/*Motor信号处理器*/
void Motor_Process(Queue2 *RawAnglePool, MotorInfo *MotorPool);

/*电机当前角度返回函数*/
float Get_CurrentAngle(const uint8_t id);
#endif //INTERFACE_MOTOR_H
